import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";

/**
 * DimensionConfig - 数据维度配置 model
 * @date:  2019-7-16
 */
import { getResponse, createPagination } from 'utils/utils';
import { queryIdpValue } from 'cpaas-front/lib/services/api';
import { queryLovHeadersList as _queryLovHeadersList, updateLovHeaders as _updateLovHeaders, insertLovHeaders as _insertLovHeaders, deleteLovHeaders as _deleteLovHeaders, updateLovValues, insertLovValues, deleteLovValues as _deleteLovValues, queryLovValues as _queryLovValues, queryLovHeader as _queryLovHeader, copyLov as _copyLov } from "../services/dimensionConfigService";
export default {
  namespace: 'dimensionConfig',
  state: {
    list: {},
    rowData: [],
    lovType: [],
    // 值集类型快码
    lovId: null,
    pagination: {} // 列表分页数据

  },
  effects: {
    // 查询值集头列表
    queryLovHeadersList: /*#__PURE__*/_regeneratorRuntime.mark(function queryLovHeadersList(_ref, _ref2) {
      var payload, call, put, all, _yield$all, _yield$all2, listResult, lovTypeResult, list, lovType, pagination;

      return _regeneratorRuntime.wrap(function queryLovHeadersList$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put, all = _ref2.all;
              _context.next = 4;
              return all([call(_queryLovHeadersList, payload), call(queryIdpValue, 'CPFM.LOV.LOV_TYPE')]);

            case 4:
              _yield$all = _context.sent;
              _yield$all2 = _slicedToArray(_yield$all, 2);
              listResult = _yield$all2[0];
              lovTypeResult = _yield$all2[1];
              list = getResponse(listResult);
              lovType = getResponse(lovTypeResult);
              pagination = createPagination(list);
              _context.next = 13;
              return put({
                type: 'updateState',
                payload: {
                  list: list,
                  lovType: lovType,
                  pagination: pagination
                }
              });

            case 13:
            case "end":
              return _context.stop();
          }
        }
      }, queryLovHeadersList);
    }),
    // 根据 ID 查询值集头
    queryLovHeader: /*#__PURE__*/_regeneratorRuntime.mark(function queryLovHeader(_ref3, _ref4) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function queryLovHeader$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call;
              _context2.next = 4;
              return call(_queryLovHeader, payload);

            case 4:
              res = _context2.sent;
              return _context2.abrupt("return", res);

            case 6:
            case "end":
              return _context2.stop();
          }
        }
      }, queryLovHeader);
    }),
    // 查询独立值集值
    queryLovValues: /*#__PURE__*/_regeneratorRuntime.mark(function queryLovValues(_ref5, _ref6) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function queryLovValues$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref5.payload;
              call = _ref6.call;
              _context3.next = 4;
              return call(_queryLovValues, payload);

            case 4:
              res = _context3.sent;
              return _context3.abrupt("return", res);

            case 6:
            case "end":
              return _context3.stop();
          }
        }
      }, queryLovValues);
    }),
    // 批量插入值集头
    insertLovHeaders: /*#__PURE__*/_regeneratorRuntime.mark(function insertLovHeaders(_ref7, _ref8) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function insertLovHeaders$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref7.payload;
              call = _ref8.call;
              _context4.next = 4;
              return call(_insertLovHeaders, payload);

            case 4:
              res = _context4.sent;
              return _context4.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context4.stop();
          }
        }
      }, insertLovHeaders);
    }),
    // 批量更新值集头
    updateLovHeaders: /*#__PURE__*/_regeneratorRuntime.mark(function updateLovHeaders(_ref9, _ref10) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function updateLovHeaders$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref9.payload;
              call = _ref10.call;
              _context5.next = 4;
              return call(_updateLovHeaders, payload);

            case 4:
              res = _context5.sent;
              return _context5.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context5.stop();
          }
        }
      }, updateLovHeaders);
    }),
    // 保存值集头
    saveLovHeaders: /*#__PURE__*/_regeneratorRuntime.mark(function saveLovHeaders(_ref11, _ref12) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function saveLovHeaders$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref11.payload;
              call = _ref12.call;

              if (!payload.lovId) {
                _context6.next = 8;
                break;
              }

              _context6.next = 5;
              return call(_updateLovHeaders, payload);

            case 5:
              res = _context6.sent;
              _context6.next = 11;
              break;

            case 8:
              _context6.next = 10;
              return call(_insertLovHeaders, payload);

            case 10:
              res = _context6.sent;

            case 11:
              return _context6.abrupt("return", getResponse(res));

            case 12:
            case "end":
              return _context6.stop();
          }
        }
      }, saveLovHeaders);
    }),
    // 批量删除值集头
    deleteLovHeaders: /*#__PURE__*/_regeneratorRuntime.mark(function deleteLovHeaders(_ref13, _ref14) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteLovHeaders$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref13.payload;
              call = _ref14.call;
              _context7.next = 4;
              return call(_deleteLovHeaders, payload);

            case 4:
              res = _context7.sent;
              return _context7.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context7.stop();
          }
        }
      }, deleteLovHeaders);
    }),
    // 保存值集值
    saveLovValues: /*#__PURE__*/_regeneratorRuntime.mark(function saveLovValues(_ref15, _ref16) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function saveLovValues$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              payload = _ref15.payload;
              call = _ref16.call;

              if (!payload.lovValueId) {
                _context8.next = 8;
                break;
              }

              _context8.next = 5;
              return call(updateLovValues, payload);

            case 5:
              res = _context8.sent;
              _context8.next = 11;
              break;

            case 8:
              _context8.next = 10;
              return call(insertLovValues, payload);

            case 10:
              res = _context8.sent;

            case 11:
              return _context8.abrupt("return", getResponse(res));

            case 12:
            case "end":
              return _context8.stop();
          }
        }
      }, saveLovValues);
    }),
    // 删除值集值
    deleteLovValues: /*#__PURE__*/_regeneratorRuntime.mark(function deleteLovValues(_ref17, _ref18) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteLovValues$(_context9) {
        while (1) {
          switch (_context9.prev = _context9.next) {
            case 0:
              payload = _ref17.payload;
              call = _ref18.call;
              _context9.next = 4;
              return call(_deleteLovValues, payload);

            case 4:
              res = _context9.sent;
              return _context9.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context9.stop();
          }
        }
      }, deleteLovValues);
    }),
    // 复制值集
    copyLov: /*#__PURE__*/_regeneratorRuntime.mark(function copyLov(_ref19, _ref20) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function copyLov$(_context10) {
        while (1) {
          switch (_context10.prev = _context10.next) {
            case 0:
              payload = _ref19.payload;
              call = _ref20.call;
              _context10.next = 4;
              return call(_copyLov, payload);

            case 4:
              res = _context10.sent;
              return _context10.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context10.stop();
          }
        }
      }, copyLov);
    })
  },
  reducers: {
    // 批量条件查询值集头
    updateState: function updateState(state, action) {
      return _objectSpread(_objectSpread({}, state), action.payload);
    }
  }
};